Conversation
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds an endpoint to move a composite sub-modification and implements the backend flow: controller → rebuild layer → study service → network service. Also expands composite UUIDs to leaf UUIDs when excluding modifications and adds tests covering move scenarios and composite expansion. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant StudyController
participant RebuildNodeService
participant StudyService
participant NetworkModificationService
Client->>StudyController: PUT /v1/studies/{studyUuid}/nodes/{nodeUuid}/composite-sub-modification/{modificationUuid}?sourceCompositeUuid=&targetCompositeUuid=&beforeUuid=
StudyController->>RebuildNodeService: moveSubModification(studyUuid, nodeUuid, sourceCompositeUuid, targetCompositeUuid, modificationUuid, beforeUuid, userId)
RebuildNodeService->>StudyService: invalidateNodeTreeWhenMoveModification(studyUuid, nodeUuid)
RebuildNodeService->>StudyService: moveSubModification(..., userId)
StudyService->>NetworkModificationService: moveSubModification(groupUuid, sourceCompositeUuid, targetCompositeUuid, modificationUuid, beforeUuid)
NetworkModificationService->>NetworkModificationService: build PUT to /groups/{groupUuid}/sub-modifications/{modificationUuid}?...
NetworkModificationService-->>NetworkModificationService: execute PUT (no body)
NetworkModificationService-->>StudyService: return
StudyService->>StudyService: emit element-updated, end notifications
RebuildNodeService->>StudyService: unblockNodeTree(studyUuid, nodeUuid) (finally)
StudyController-->>Client: 200 OK
Suggested reviewers
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 ast-grep (0.41.1)src/main/java/org/gridsuite/study/server/service/StudyService.javaThanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Signed-off-by: Mathieu DEHARBE <mathieu.deharbe@rte-france.com>
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (4)
src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java (2)
410-437: Add explicit precondition checks for required UUIDs.
groupUuidandmodificationUuidare mandatory for URI expansion; guard them at method entry to fail fast with a clear contract.♻️ Proposed change
public void moveSubModification( UUID groupUuid, UUID sourceCompositeUuid, UUID targetCompositeUuid, UUID modificationUuid, UUID beforeUuid) { + Objects.requireNonNull(groupUuid, "groupUuid is required"); + Objects.requireNonNull(modificationUuid, "modificationUuid is required"); var path = UriComponentsBuilder.fromPath( COMPOSITE_PATH + "groups" + DELIMITER + "{groupUuid}" + DELIMITER + "sub-modifications" + DELIMITER + "{modificationUuid}");🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java` around lines 410 - 437, The method moveSubModification should validate required UUID parameters up front: add explicit null-check preconditions for groupUuid and modificationUuid (used in URI expansion) at the start of moveSubModification and throw a clear IllegalArgumentException (or use Objects.requireNonNull) with descriptive messages; keep existing optional handling for sourceCompositeUuid, targetCompositeUuid, and beforeUuid unchanged so the rest of the method can assume groupUuid and modificationUuid are non-null when building the path and calling restTemplate.put.
439-450: Short-circuit empty input and return a null-safe set.For an empty list, this can return immediately without a remote call; also avoid leaking a null body to callers.
♻️ Proposed change
public Set<UUID> expandToLeafUuids(List<UUID> modificationUuids) { + Objects.requireNonNull(modificationUuids, "modificationUuids is required"); + if (modificationUuids.isEmpty()) { + return Set.of(); + } + var path = UriComponentsBuilder.fromPath(COMPOSITE_PATH + "leaf-uuids") .queryParam("uuids", modificationUuids) .toUriString(); - return restTemplate.exchange( + Set<UUID> body = restTemplate.exchange( getNetworkModificationServerURI(false) + path, HttpMethod.GET, null, new ParameterizedTypeReference<Set<UUID>>() { } - ).getBody(); + ).getBody(); + return body != null ? body : Set.of(); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java` around lines 439 - 450, The expandToLeafUuids method should short-circuit when modificationUuids is empty and always return a non-null Set to callers; change expandToLeafUuids to check modificationUuids.isEmpty() and return Collections.emptySet() (or Set.of()) immediately instead of calling restTemplate.exchange, and after the remote call ensure the result from restTemplate.exchange(...).getBody() is null-checked and replaced with an empty Set before returning; reference expandToLeafUuids, COMPOSITE_PATH, restTemplate.exchange and getNetworkModificationServerURI to locate the changes.src/test/java/org/gridsuite/study/server/NetworkModificationTest.java (2)
3138-3139: Make move-case query assertions strict (including absent params).Line 3138 and Line 3154 only assert required params, so these cases can still pass if unwanted query params are forwarded. Assert missing params explicitly.
♻️ Proposed test hardening
- WireMockUtilsCriteria.verifyPutRequest(wireMockServer, moveSubModifUrlPattern, false, Map.of( - "targetCompositeUuid", WireMock.equalTo(targetCompositeUuid.toString())), null); + WireMockUtilsCriteria.verifyPutRequest(wireMockServer, moveSubModifUrlPattern, false, Map.of( + "targetCompositeUuid", WireMock.equalTo(targetCompositeUuid.toString()), + "sourceCompositeUuid", WireMock.absent(), + "beforeUuid", WireMock.absent()), null); ... - WireMockUtilsCriteria.verifyPutRequest(wireMockServer, moveSubModifUrlPattern, false, Map.of( - "sourceCompositeUuid", WireMock.equalTo(sourceCompositeUuid.toString())), null); + WireMockUtilsCriteria.verifyPutRequest(wireMockServer, moveSubModifUrlPattern, false, Map.of( + "sourceCompositeUuid", WireMock.equalTo(sourceCompositeUuid.toString()), + "targetCompositeUuid", WireMock.absent(), + "beforeUuid", WireMock.absent()), null);Also applies to: 3154-3155
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/gridsuite/study/server/NetworkModificationTest.java` around lines 3138 - 3139, The verifyPutRequest call is only checking required params and allows unwanted query params to slip through; update the WireMockUtilsCriteria.verifyPutRequest invocations for moveSubModifUrlPattern (the call using targetCompositeUuid) and the similar call later to assert absent params explicitly by adding the expected absent query keys to the Map of matchers using WireMock.absent() (or the project's equivalent absent matcher) for keys that must not be forwarded, while keeping WireMock.equalTo(targetCompositeUuid.toString()) for the required "targetCompositeUuid".
3211-3216: Assert exact exclusion UUID set, not a superset.Line 3214 currently accepts any superset. Use exact-set equality so the test fails when unexpected UUIDs are included.
♻️ Proposed assertion tightening
+ Set<UUID> expectedExcluded = new HashSet<>(expandedLeafUuids); + expectedExcluded.add(compositeUuid); verify(rootNetworkNodeInfoService, times(1)).updateModificationsToExclude( eq(nodeUuid), eq(rootNetworkUuid), - argThat((Set<UUID> uuids) -> uuids.contains(compositeUuid) - && uuids.containsAll(expandedLeafUuids)), + argThat(expectedExcluded::equals), eq(false));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/test/java/org/gridsuite/study/server/NetworkModificationTest.java` around lines 3211 - 3216, The test currently allows a superset because argThat checks contains/composite and containsAll; change the assertion in NetworkModificationTest so the UUID set is compared for exact equality instead of subset/superset checks: construct the expected Set<UUID> containing compositeUuid plus expandedLeafUuids and replace argThat((Set<UUID> uuids) -> uuids.contains(compositeUuid) && uuids.containsAll(expandedLeafUuids)) with an argument matcher that calls equals(expectedSet) (or use eq(expectedSet)) when verifying rootNetworkNodeInfoService.updateModificationsToExclude(...), so unexpected UUIDs will fail the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/main/java/org/gridsuite/study/server/service/StudyService.java`:
- Around line 2395-2411: The end notification and emitElementUpdated must run
even if networkModificationService.moveSubModification throws; wrap the call to
networkModificationService.moveSubModification(...) in a try/finally so
notificationService.emitEndModificationEquipmentNotification(studyUuid,
nodeUuid, childrenUuids) and notificationService.emitElementUpdated(studyUuid,
userId) are executed in the finally block; preserve the initial calls to
getChildrenUuids and checkStudyContainsNode, rethrow the exception after the
finally block (or allow it to propagate) so existing error behavior is
unchanged.
- Line 2174: The code in StudyService mutates the caller-provided Set
modificationsUuids in-place; avoid this by creating a new mutable collection for
the expanded UUIDs instead of calling modificationsUuids.addAll(...). Call
networkModificationService.expandToLeafUuids(...) with a copy of the incoming
collection if needed, collect the returned UUIDs into a new Set or List (e.g.,
expandedUuids), then use that new collection for downstream logic; reference the
existing symbols modificationsUuids and
networkModificationService.expandToLeafUuids to locate and replace the in-place
addAll with creation of a fresh collection that merges the original and expanded
results without mutating the parameter.
---
Nitpick comments:
In
`@src/main/java/org/gridsuite/study/server/service/NetworkModificationService.java`:
- Around line 410-437: The method moveSubModification should validate required
UUID parameters up front: add explicit null-check preconditions for groupUuid
and modificationUuid (used in URI expansion) at the start of moveSubModification
and throw a clear IllegalArgumentException (or use Objects.requireNonNull) with
descriptive messages; keep existing optional handling for sourceCompositeUuid,
targetCompositeUuid, and beforeUuid unchanged so the rest of the method can
assume groupUuid and modificationUuid are non-null when building the path and
calling restTemplate.put.
- Around line 439-450: The expandToLeafUuids method should short-circuit when
modificationUuids is empty and always return a non-null Set to callers; change
expandToLeafUuids to check modificationUuids.isEmpty() and return
Collections.emptySet() (or Set.of()) immediately instead of calling
restTemplate.exchange, and after the remote call ensure the result from
restTemplate.exchange(...).getBody() is null-checked and replaced with an empty
Set before returning; reference expandToLeafUuids, COMPOSITE_PATH,
restTemplate.exchange and getNetworkModificationServerURI to locate the changes.
In `@src/test/java/org/gridsuite/study/server/NetworkModificationTest.java`:
- Around line 3138-3139: The verifyPutRequest call is only checking required
params and allows unwanted query params to slip through; update the
WireMockUtilsCriteria.verifyPutRequest invocations for moveSubModifUrlPattern
(the call using targetCompositeUuid) and the similar call later to assert absent
params explicitly by adding the expected absent query keys to the Map of
matchers using WireMock.absent() (or the project's equivalent absent matcher)
for keys that must not be forwarded, while keeping
WireMock.equalTo(targetCompositeUuid.toString()) for the required
"targetCompositeUuid".
- Around line 3211-3216: The test currently allows a superset because argThat
checks contains/composite and containsAll; change the assertion in
NetworkModificationTest so the UUID set is compared for exact equality instead
of subset/superset checks: construct the expected Set<UUID> containing
compositeUuid plus expandedLeafUuids and replace argThat((Set<UUID> uuids) ->
uuids.contains(compositeUuid) && uuids.containsAll(expandedLeafUuids)) with an
argument matcher that calls equals(expectedSet) (or use eq(expectedSet)) when
verifying rootNetworkNodeInfoService.updateModificationsToExclude(...), so
unexpected UUIDs will fail the test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 8c7fecd4-b51b-49e7-b24d-2837a2aa36c8
📒 Files selected for processing (5)
src/main/java/org/gridsuite/study/server/controller/StudyController.javasrc/main/java/org/gridsuite/study/server/service/NetworkModificationService.javasrc/main/java/org/gridsuite/study/server/service/RebuildNodeService.javasrc/main/java/org/gridsuite/study/server/service/StudyService.javasrc/test/java/org/gridsuite/study/server/NetworkModificationTest.java
src/main/java/org/gridsuite/study/server/service/StudyService.java
Outdated
Show resolved
Hide resolved
… mutating issues down the line
|



PR Summary